{include file="common/head"}
<style>
    a {
        text-decoration: none;
    }

    input {
        display: initial !important;
    }
</style>
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
<script src="/static/flatpickr/flatpickr.min.js"></script>
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                <form action="/index.php/order/index" method="post">
                    <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                        <input type="hidden" name="status" value="{$status}" />
                        <div class="col-1">
                            <h3>订单管理</h3>
                        </div>
                        <div class="col">
                            
                            <label for="customer">状态：</label>
                            <select name="status" class="form-control" style="width:100px;display:initial;">
                                <option value="">所有</option>
                                {foreach $status_list as $k=>$v}
                                <option value="{$k}" {if $k==$status}selected{/if}>{$v[0]}</option>
                                {/foreach}
                            </select>

                            <label for="sdate">日期：</label>
                            <input class="form-control" type="text" value="{$sdate}" id="sdate" name="sdate"
                                placeholder="开始日期" />

                            <label for="sdate"></label>
                            <input class="form-control" type="text" value="{$edate}" id="edate" name="edate"
                                placeholder="结束日期" />

                            <label for="po">订单号</label>
                            <input class="form-control" type="text" value="{$po}" id="po" name="po"
                                placeholder="订单号" />
                            </label>
                            <label for="goods_name">产品</label>
                            <input class="form-control" type="text" value="{$goods_name}" id="goods_name" name="goods_name"
                                placeholder="品名" />
                            </label>

                            <button type="button" class="btn btn-warning query">
                                <span class="bi-search"></span>
                            </button>
                        </div>

                    </div>
                </form>
            </div>
        </div>

        <table class="table table-sm table-hover table-striped table-bordered" >
            <thead class="table-info">
                <th>序号 SN</th>
                <th>订单号</th>
                <th>客户</th>
                <th>产品x天数</th>
                <th>订单金额</th>
                <th>订单天数</th>
                <th>投放时间</th>
                <th>结束日期</th>
                <th>剩余时间</th>
                <th>备注 Memo</th>
                <th>订单状态</th>

                <th>

                </th>
            </thead>
            <tbody>
                {foreach $list['data'] as $k=>$kv}
                <tr>
                    <td>{$k+1}</td>
                    <td>{$kv['order_no']}</td>
                    <td>{$kv['user_id_name']}</td>  
                    <th>{$kv['goods_list']}</th>
                    <td class="text-center">{$currency_symbol}{$kv['amount']}</td>
                    <td class="text-center">{$kv['qty']}</td>
                    <td>{$kv['start_time']}</td>
                    <td>{$kv['end_time']}</td>
                    <td>{$kv['days_left']}</td>
                    <td>{$kv['memo']}</td>
                    <td style="color:{if $kv.status==3}#f60;{elseif $kv.status==4}blue;{/if}">{$kv['status_name'][0]}</td>


                    <td class="text-nowrap">


                        {if $kv['status']==1}
                        <button tyle="button" class="btn btn-sm btn-success" oid="{$kv['id']}">
                            <span class="bi-check"></span>
                        </button>

                        <button tyle="button" class="btn btn-sm btn-danger btn_cancel" oid="{$kv['id']}">
                            <span class="bi-trash"></span>
                        </button>
                        {/if}



                    </td>
                </tr>
                {/foreach}

            </tbody>
        </table>
        {include file="common/pagination"}
    </div>

</body>

<script type="text/javascript">
    flatpickr("#sdate,#edate", {});

    $(document).ready(function () {
        setTimeout(function () { $(".query").show() }, 3000);

        $(".list").on('click', function () {
            var oid = $(this).attr('oid');
            layer.open({
                type: 2,
                title: '订单明细',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content: '/index.php/order/order_list/id/' + oid
            });
        })

        $(".bi-check").on('click', function () {
            var oid = $(this).parent().attr('oid');
            layer.confirm('请在确认之前，仔细检查订单产品规格及数量！！！？', {
                btn: ['已经确认好了', '再检查一下'] //按钮
            }, function () {

                $.post("/order/order_check", {table:'order', id: oid, status: 2 }, function (res) {
                    if (res.code) {
                        layer.msg('订单已确认!');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                        
                    } else {
                        layer.open({ content: '失败!' });
                    }
                });

            }, function () {
                layer.msg('取消操作!');
            });
        })


        $(".btn_cancel").on('click', function () {
            var oid = $(this).attr('oid');
            layer.confirm('确认把订单丢进垃圾筒吗？', {
                btn: ['Yes', 'No'] //按钮
            }, function () {

                $.post("/index.php/order/order_cancel", { table: 'order', id: oid }, function (res) {
                    console.log(res.msg)
                    if (res.code) {
                        location.reload();
                    } else {
                        layer.open({ 'content': res.msg });
                    }

                });

            }, function () {
                layer.msg('取消操作!');
            });

        })


        $(".query").on('click', function () {
            var cid = $("#customer_id").val();
            var order_no = $("#order_no").val();
            var sdate = $("#sdate").val();
            var edate = $("#edate").val();
            $("form").submit();
        })


    })



</script>

</body>

</html>